﻿// CSelDateDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "DC-QC.h"
#include "CSelDateDlg.h"
#include "afxdialogex.h"


// CSelDateDlg 对话框

IMPLEMENT_DYNAMIC(CSelDateDlg, CDialogEx)

CSelDateDlg::CSelDateDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_SELDATEDLG, pParent)
{

}

CSelDateDlg::~CSelDateDlg()
{
}

void CSelDateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_DATETIMEPICKER1, m_ctlDate);
}


BEGIN_MESSAGE_MAP(CSelDateDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CSelDateDlg::OnBnClickedOk)
	ON_WM_PAINT()
	ON_WM_CTLCOLOR()
END_MESSAGE_MAP()


// CSelDateDlg 消息处理程序


BOOL CSelDateDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	m_ctlDate.SetFormat(_T("yyyy-MM-dd  HH:mm:ss"));
	m_ctlDate.SetTime(m_tDbEndTime.GetTime()-12*60*60);

	CString strTemp;
	strTemp.Format(_T("(本井色谱数据时间范围为：%s 至 %s)"), m_tDbStartTime.Format(_T("%m-%d %H:%M")), m_tDbEndTime.Format(_T("%m-%d %H:%M")));
	GetDlgItem(IDC_STATICINOF)->SetWindowTextW(strTemp);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CSelDateDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	m_ctlDate.GetTime(m_tSel);
	if (m_tSel< m_tDbStartTime-CTimeSpan(1,0,0,0) || m_tSel>m_tDbEndTime)
	{
		AfxMessageBox(_T("所选时间超出数据库中数据起止时间范围！\n\n请重新选择！"), MB_ICONINFORMATION);
		return;
	}
	CDialogEx::OnOK();
}


void CSelDateDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting
					   // TODO: 在此处添加消息处理程序代码
					   // 不为绘图消息调用 CDialogEx::OnPaint()
	CRect rect;
	GetClientRect(&rect);

	CBitmap ClientScreen, *pOldBitmap;
	CRect UpdateRect(rect);
	CDC MDC;
	MDC.CreateCompatibleDC(&dc);
	ClientScreen.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
	pOldBitmap = MDC.SelectObject(&ClientScreen);
	MDC.FillSolidRect(UpdateRect, RGB(255, 255, 255));
	Draw(&MDC, rect);
	dc.BitBlt(UpdateRect.left, UpdateRect.top,
		UpdateRect.right - UpdateRect.left,
		UpdateRect.bottom - UpdateRect.top,
		&MDC, UpdateRect.left, UpdateRect.top, SRCCOPY);
	MDC.SelectObject(pOldBitmap);

	ClientScreen.DeleteObject();
	MDC.DeleteDC();
}

void	CSelDateDlg::Draw(CDC* pDC, CRect rt)
{
	DrawInBorder(pDC, rt);
	rt.DeflateRect(1, 1, 1, 1);
	BxGradientFill(pDC, rt, BACKCOLOR1, BACKCOLOR1, 1);
}

HBRUSH CSelDateDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何特性
	if (nCtlColor == CTLCOLOR_STATIC)
	{
		pDC->SetBkMode(TRANSPARENT);
		return gl.m_brBack1;
	}
	// TODO:  如果默认的不是所需画笔，则返回另一个画笔
	return hbr;
}
